<%@ include file="/common/taglibs.jsp"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<head>
<title>在建公路,水运工程项目原材料试验及现场检测月度统计表</title>
<%@ include file="/common/extjs.jsp"%>
<script type="text/javascript"
	src="<c:url value='/ext/plugin/FieldTip.js'/>" charset="utf-8"></script>
<style>
<!--
.noEditColor {
	background: #CCCCCC;
}
-->
</style>
<script type="text/javascript">
var  app ={};
Ext.onReady(function(){
 Ext.QuickTips.init();
 	var fm = Ext.form;
 	 var groupHeader = new Ext.ux.grid.ColumnHeaderGroup({
        rows: [
		[
			{header: '', colspan: 3, align: 'center'},
			{header: '进场批次及数量', colspan: 2, align: 'center'},
			{header: '施工自检(数量/批次)', colspan: 10, align: 'center'},
			{header: '监理抽检(次数/批数)', colspan: 10, align: 'center'},
			{header: '', colspan: 2, align: 'center'}
		],
		[
			{header: '', colspan: 3, align: 'center'},
			{header: '(数量/批次)', colspan: 2, align: 'center'},
			{header: '规定', colspan: 2, align: 'center'},
			{header: '自检', colspan: 2, align: 'center'},
			{header: '合格', colspan: 2, align: 'center'},
			{header: '合格率(%)', colspan: 2, align: 'center'},
			{header: '频率(%)', colspan: 2, align: 'center'},
			{header: '规定', colspan: 2, align: 'center'},
			{header: '抽检', colspan: 2, align: 'center'},
			{header: '合格', colspan: 2, align: 'center'},
			{header: '合格率(%)', colspan: 2, align: 'center'},
			{header: '频率(%)', colspan: 2, align: 'center'},
			{header: '', colspan: 2, align: 'center'},
		],
         	  ]
    });
 	 
    var cm = new Ext.grid.ColumnModel({
    	columns:[
		new Ext.grid.RowNumberer({header:'序号',width: 30}),
    	{
    		header:'工程部位',
    	 	dataIndex: 'unit',
            width: 120,
            editor:true
    	}
    	,{
    		header:'试验类别',
    	 	dataIndex: 'category',
            width: 70
    	},{
    		 header:'本月',
    	 	dataIndex: 'arrivalMonth',
            width: 70
    	},{
    		header:'累计',
    	 	dataIndex: 'arrivalTotal',
            width: 70
    	},{
   		 header:'本月',
	 	dataIndex: 'planMonth',
        width: 70
	},{
		header:'累计',
	 	dataIndex: 'planTotal',
        width: 70
	},{
    		header:'本月',
    	 	dataIndex: 'countMonth',
            width: 70
    	},
    	{
    		header:'累计',
    	 	dataIndex: 'countTotal',
            width: 70
    	},{
    		header:'本月',
    	 	dataIndex: 'passMonth',
            width: 70
    	},
    	{
    		header:'累计',
    	 	dataIndex: 'passTotal',
            width: 70
    	},{
    		header:'本月',
    	 	dataIndex: 'selfYieldM',
            width: 70,
            renderer:Jinyi.project.Format.percentRenderer
    	},{
    		header:'累计',
    	 	dataIndex: 'selfYieldT',
            width: 75,
            renderer:Jinyi.project.Format.percentRenderer
    	},{
    		header:'本月',
    	 	dataIndex: 'selfRateM',
            width: 70  ,
            renderer:Jinyi.project.Format.percentRenderer
    	},{
    		header:'累计',
    	 	dataIndex: 'selfRateT',
            width: 70,
            renderer:Jinyi.project.Format.percentRenderer
    	},{
    		header:'本月',
    	 	dataIndex: 'splanMonth',
            width: 70
    	},{
    		header:'累计',
    	 	dataIndex: 'splanTotal',
            width: 70
    	},{
    		header:'本月',
    	 	dataIndex: 'scountMonth',
            width: 70
    	},{
    		header:'累计',
    	 	dataIndex: 'scountTotal',
            width: 70     
    	},{
    		header:'本月',
    	 	dataIndex: 'spassMonth',
            width: 70
    	},{
    		header:'累计',
    	 	dataIndex: 'spassTotal',
            width: 70     
    	},{
    		header:'本月',   		
    	 	dataIndex: 'randomYieldM',
            width: 70,
            renderer:Jinyi.project.Format.percentRenderer
    	},{
    		header:'累计' ,
    	 	dataIndex: 'randomYieldT',
            width: 70,
            renderer:Jinyi.project.Format.percentRenderer
    	},{
    		header:'本月' ,
    	 	dataIndex: 'randomRateM',
            width: 70,
            renderer:Jinyi.project.Format.percentRenderer
    	}, {
    		header:'累计' ,
    	 	dataIndex: 'randomRateT',
            width: 70,
            renderer:Jinyi.project.Format.percentRenderer
    	},{
    		header:'附件' ,
    	 	dataIndex: 'attachment',
            width: 70
    	}, {
    		header:'备注' ,
    	 	dataIndex: 'remark',
            width: 70
    	}
    	],
    	defaults : {
    		align : 'center',
            sortable: true    
        },	
        isCellEditable: function(col, row) {
    	//	var record = store.getAt(row);
    		return Ext.grid.ColumnModel.prototype.isCellEditable.call(this, col, row);
  		}
    });

  var Record = new Ext.data.Record.create([  
	  	{name:'id',type:'string'},
	  	{name:'pid',type:'string'},//工程ID
	  	{name:'sid',type:'string'},  //合同段Id
	  	{name:'unit',type:'string'},  //单位工程
	  	{name:'category',type:'string'}, //试验类别
	
	  	{name:'arrivalMonth',type:'float'},    
		{name:'arrivalTotal',type:'float'}, 
		{name:'planMonth',type:'float'},  
		{name:'planTotal',type:'float'},   
		{name:'countMonth',type:'float'},  
		{name:'countTotal',type:'float'},   
		{name:'passMonth',type:'float'},   
   	    {name:'passTotal',type:'float'}, 
   	    
   	 	{name:'selfYieldM',type:'float'},  
		{name:'selfYieldT',type:'float'},   
		{name:'selfRateM',type:'float'},   
	    {name:'selfRateT',type:'float'}, 
	    
   		{name:'splanMonth',type:'float'},  
		{name:'splanTotal',type:'float'},   
		{name:'scountMonth',type:'float'},  
		{name:'scountTotal',type:'float'},   
		{name:'spassMonth',type:'float'},   
   	    {name:'spassTotal',type:'float'}, 
   	    
   		{name:'randomYieldM',type:'float'},  
		{name:'randomYieldT',type:'float'},   
		{name:'randomRateM',type:'float'},   
	    {name:'randomRateT',type:'float'},
	    {name:'attachment',type:'string'},
	    {name:'remark',type:'string'}
  ]);
  
	var conSignCombo = new fm.ComboBox({
        typeAhead: true,
        triggerAction: 'all',
        transform:'conSign',
        lazyRender:true,
        listClass: 'x-combo-list-small',
        allowBlank: true,
        width :70,
        selectOnFocus : true,
        listeners : {
        	select : function(combo,record,index ){                	           		
        		villageStore.baseParams.numberId = record.get("numberId");
        		villageStore.load();
        	}
        }
    })
	
	
	
	
	var  villageStore =new Ext.data.JsonStore({  //所属村庄store
		url: appConfig.contPath + '/report/ext/materialtest.action',
		baseParams :{
			conSignId:conSignId,
			method: 'getBatch'
		},	
		root: 'results', 
		fields:['value', 'text']	
	 });
	
	var villageCombo = new Ext.ux.form.LovCombo({   //所属村庄combo
				typeAhead: false,
               triggerAction: 'all',
               lazyRender:false,
               editable:true,
               listClass: 'x-combo-list-small',
               store: villageStore,
                mode:'remote',
                beforeBlur: Ext.emptyFn,
                triggerAction:'all',
                hideOnSelect:false,
                forceSelection : true,   
                selectOnFocus : true,
                valueField:'value',
                displayField:'text',
                triggerAction : 'all',   
                typeAhead : true               
	});
	var numberCombo = new Ext.form.ComboBox({  //所属乡镇combo
                listeners : {
                	select : function(combo,record,index ){                	           		
                		villageStore.baseParams.conSignId = record.get("numberId");
                		villageStore.load();
                	}
                }
	});
	
  
  var store =new  Ext.data.Store({
  		url: appConfig.contPath + '/report/materialtest.action',
		baseParams :{
			projectId : '${param.projectId}'
					},
       	    reader: new Ext.data.JsonReader({
        		totalProperty: 'totalCounts',
             	root: 'results',
             	id: 'id'
           }, Record)
  });
  
	var grid =new  Ext.grid.EditorGridPanel({
		cm: cm,
        iconCls:'grid-columns-icon',
		frame:true,
		store: store,
		clicksToEdit: 1,
		title : "进度管理",
		stripeRows: true,	
		listeners: {
        	render: function(g) {    	
        	  		searchData();	 	
        	},
        	afteredit : function(e){
        		var record = e.record;
				switch(e.field){
					case 'finishInvestmentThis' :  //本年本次完成投资
					{					
						var result  = new Number(0);
						var finishInvestmentLast = new Number(record.get("finishInvestmentLast")); //本年上次累计完成投资
						var finishInvestmentThis = new Number(record.get("finishInvestmentThis")); //本年本次完成投资
						
						var finishInvestmentThisYear = finishInvestmentLast + finishInvestmentThis; //本年完成投资
						record.set("finishInvestmentThisYear",finishInvestmentThisYear);    //设置本年完成投资
						
						var finishInvestmentLastYear = new Number(record.get("finishInvestmentLastYear")); //上年累计完成投资
						var finishInvestmentTotal = finishInvestmentLastYear + finishInvestmentThisYear;
						record.set("finishInvestmentTotal",finishInvestmentTotal);    //设置完成总投资
						
						var planInvestmentTotal = record.get("planInvestmentTotal");      //计划总投资
						if(planInvestmentTotal != 0){
							result = accDiv(finishInvestmentTotal,planInvestmentTotal).toFixed(3);
							record.set("finishInvestmentPercent",result);    //完成投资率
						}
						break ;
					};
					case  'finishMileageTotal' : {
						var result  = new Number(0);
						var finishMileageTotal = record.get("finishMileageTotal"); //完成总里程
						var toBuildLenTotal = record.get("toBuildLenTotal");      //计划总里程
						if(toBuildLenTotal != 0){
							result = accDiv(finishMileageTotal,toBuildLenTotal).toFixed(3);
							record.set("progressPercent",result);    //形象进度
						}
						break ;
					}
					case  'paymentCityFinishInvestment' :  //已到位补助资金
					case  'paymentCentralInvestment' :  //已到位中央投资
					case  'paymentOtherFinishInvestment' : {      //已到位其它     
						var result  = new Number(0);
						var paymentCityFinishInvestment = new Number(record.get("paymentCityFinishInvestment")); //已到位补助资金
						var paymentCentralInvestment = new Number(record.get("paymentCentralInvestment"));      //已到位中央投资
						var paymentOtherFinishInvestment = new Number(record.get("paymentOtherFinishInvestment"));      //已到位其它
						result = paymentCityFinishInvestment +paymentCentralInvestment +paymentOtherFinishInvestment;
						record.set("paymentInvestmentTotal",result);  //已到位总资金
					}
				}
        	},
        	delay: 10
      	},
		sm:	new Ext.grid.RowSelectionModel({singleSelect:true}),
		plugins : [groupHeader],
		region : 'center',
        loadMask:{msg :'数据加载中...'}, 
        tbar:[
				'合同段：',
				conSignCombo,
              	'->',
		   		{text: '新增',handler:function(){
		   		 var Plant = grid.getStore().recordType;
	                var p = new Plant({
	            		unit:'  ',
	            		category:' ',
	            	  	arrivalMonth:' ',
	            	  	arrivalToal:' ',
	            	  	planMonth :' ',
	            	  	planTotal: '' ,
						countMonth:'',
						countTotal :'',
						passMonth: '' ,
						passTotal :'',
						selfYieldM : '',
						selfYieldT :'',
						selfRateM :'',
						selfRateT : '' ,
						randomYieldM : '',
						randomYieldT :'',
						randomRateM :'',
						randomRateT : '' 
	                });
	                grid.stopEditing();
	                store.insert(0, p);
	                grid.startEditing(0, 1);
		   		},iconCls:'dt_flush'},'->',
    		   	"->",{text: '更新进度',handler:saveMoreData,iconCls:'dt_saveall',tooltip : "更新后,需进入右方的国省道大中修上报导航进行批量上报,否则将没有上报"},'->',
    		   		{text: '刷新',handler:searchData,iconCls:'dt_flush'},'->',
    		   		{text: '导出',handler:function(){exportExcelF(grid,"国省道大中修工程进度管理")} ,iconCls:'bt_excel'},'-',
        		'<font color="red">注:金额单位->(万元) 计划总里程,完成总里程->(公里)</font>'
			],
        bbar:[
		   		{text: '导出',handler:function(){exportExcelF(grid,"国省道大中修工程进度管理")} ,iconCls:'bt_excel'},'-',
  		'<font color="red">注:金额单位->(万元) 计划总里程,完成总里程->(公里)</font>'
		]
	});
	var viewport = new Ext.Viewport({
    layout: 'border',    
    items: [grid]
    }); 
    
/**
刷新纪录
*/
function reloadData(){
	store.removeAll();
	store.load({});
}

/**
查询纪录
*/
function searchData(){
	reloadData();
}

/**
 * 保存
 */
function saveMoreData(){
 	var modified = store.getRange();
  	var len = modified.length;
    // 如果没有修改 直接返回
   	if(len == 0){ Ext.example.msg('信息', '数据没有变动,无须保存！');return;}
   	Ext.Msg.confirm('保存操作', '请确认数据的正确性,是否继续?', function(btn, text){
   	 	if(btn == "yes"){
		  	var fields = record.prototype.fields;
		  	var jsonData = '[';
				for(var i = 0 ,ilen = modified.length; i <　ilen; i++){  
				 	var history = modified[i].get("history");
			      //  if(history=='notHistory'){ Ext.example.msg('信息', '数据上报中,无法更新!');return;}
					jsonData = jsonData+ '{';
					 for(var j = 0, jlen = fields.length; j < jlen; j++){
			            var f = fields.items[j].name;
			            var v = modified[i].get(f);
			            if(!Ext.isEmpty(v)) {
			               if(Ext.isDate(v)){
			                 v= Jinyi.project.Format.formatDateRenderer(v);
			               }
			            jsonData = jsonData +　f +　":" + Ext.encode(v);
			            if(j+1 != jlen) jsonData = jsonData+ ",";
			     		}
			     	}
			     	jsonData = jsonData + '}';
			     	if(i+1 != ilen) jsonData = jsonData+ ",";
		    	}	
		    jsonData = jsonData + ']';
		    // 数据库操作
		    Ext.Ajax.request({
		        url:  appConfig.contPath + '/construct/cpReconstructReports.html',
		        params: {
		        		method: 'saveMore',
		            	jsonStr: jsonData
		        },
		        method:'POST',
		        success: function(response, options){
		           try {
						var responseData = Ext.decode(response.responseText);
		            	if (responseData.success == true) {
			            	searchData();
			                Ext.example.msg('信息', '该工程进度更新成功,若未完工,请更新当月质量管理,进度需进行上报审核后,才报送给市局!');
		            		}else { Ext.example.msg('提示', '数据修改失败!'); }
								}catch(e) { Ext.example.msg('提示', '修改失败！请稍后再尝试');}
		        },
		        failure: function(response, options){Ext.example.msg('警告!', '服务端发生错误,数据修改失败!');}
		    }); 
	 	}
  });
}
});
</script>
</head>
<body>
<div style="display: none">
	<pt:labels type="sign" argument1="${param.projectId}" argument2="4" name="conSign" default="${conSign }" hasEmpty="false"></pt:labels>
</div>
</body>
